{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b4778164",
   "metadata": {},
   "source": [
    "* 学习方法 \n",
    "> 1. listname.Tab键 查看所有方法名称\n",
    "> 2. help(listname.function) 查看其中一个方法的具体操作内容\n",
    "\n",
    "* 1.append"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0176d682",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "7519aaa3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(object, /) method of builtins.list instance\n",
      "    Append object to the end of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.append)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4db19047",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append(\"chenzexin\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b15c703c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Jan', 'Jack', 'chenzexin']"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c21cb233",
   "metadata": {},
   "source": [
    "* 2.insert"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "a944b177",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function insert:\n",
      "\n",
      "insert(index, object, /) method of builtins.list instance\n",
      "    Insert object before index.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.insert)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "76420452",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.insert(1,\"Alex\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "a34b5e0a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Alex']"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ccf7793b",
   "metadata": {},
   "source": [
    "* 3.clear"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "2ac92932",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function clear:\n",
      "\n",
      "clear() method of builtins.list instance\n",
      "    Remove all items from list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.clear)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "1f32d86c",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "names.clear()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "63e69bd1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "792dc64a",
   "metadata": {},
   "source": [
    "* 4.count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "08890bbc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function count:\n",
      "\n",
      "count(value, /) method of builtins.list instance\n",
      "    Return number of occurrences of value.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "765eca9a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "names.count(\"Jan\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e83e91b6",
   "metadata": {},
   "source": [
    "* 5.copy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "593f8901",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function copy:\n",
      "\n",
      "copy() method of builtins.list instance\n",
      "    Return a shallow copy of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.copy)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "6e221c74",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Jan', 'Jack']"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "names.copy()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "011a6115",
   "metadata": {},
   "source": [
    "* 6.sort"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "2a2b8016",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function sort:\n",
      "\n",
      "sort(*, key=None, reverse=False) method of builtins.list instance\n",
      "    Sort the list in ascending order and return None.\n",
      "    \n",
      "    The sort is in-place (i.e. the list itself is modified) and stable (i.e. the\n",
      "    order of two equal elements is maintained).\n",
      "    \n",
      "    If a key function is given, apply it once to each list item and sort them,\n",
      "    ascending or descending, according to their function values.\n",
      "    \n",
      "    The reverse flag can be set to sort in descending order.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.sort)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "9c4a4b68",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "names.sort()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "04f7e6f1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Jan', 'Mary', 'Mike']"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "43f437da",
   "metadata": {},
   "source": [
    "* 7.reverse"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "cd0ffb6a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function reverse:\n",
      "\n",
      "reverse() method of builtins.list instance\n",
      "    Reverse *IN PLACE*.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.reverse)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "33f67a4a",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "names.reverse()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "a40ccaca",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Jan', 'Mary', 'Mike']"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ded7837c",
   "metadata": {},
   "source": [
    "* 8.remove"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "3d3643c6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function remove:\n",
      "\n",
      "remove(value, /) method of builtins.list instance\n",
      "    Remove first occurrence of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.remove)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "e56c391a",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "names.remove(\"Mary\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "d9c6b80c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Jan', 'Jack']"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0d92cbe9",
   "metadata": {},
   "source": [
    "* 9.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "cbb1e762",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function index:\n",
      "\n",
      "index(value, start=0, stop=9223372036854775807, /) method of builtins.list instance\n",
      "    Return first index of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "9e56fdec",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "names.index(\"Mary\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "38729054",
   "metadata": {},
   "source": [
    "* 10.pop"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "7af15869",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function pop:\n",
      "\n",
      "pop(index=-1, /) method of builtins.list instance\n",
      "    Remove and return item at index (default last).\n",
      "    \n",
      "    Raises IndexError if list is empty or index is out of range.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.pop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "686eb6bc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Jack'"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "names.pop(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cda9077a",
   "metadata": {},
   "source": [
    "* 11.extend"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "8d3c0e2c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function extend:\n",
      "\n",
      "extend(iterable, /) method of builtins.list instance\n",
      "    Extend list by appending elements from the iterable.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.extend)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "431d528f",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "names.extend(\"Mike\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "da33cc3b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Jan', 'Jack', 'M', 'i', 'k', 'e']"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "26361eb6",
   "metadata": {},
   "source": [
    "| 列表方法    | Description |  example    |  备注     |\n",
    "| :-----------:|:-----------:  | :-----------: | :-----------:  |\n",
    "| append()  |增加元素，增加在列表的末尾|  详见1.append | 记得运行前面代码  |\n",
    "| insert()  |在索引前添加目标对象 | 详见2.insert     | 注意结果是插入在检索元素前面  |\n",
    "| clear()   | 清除列表中所有元素 | 详见3.clear      | 清除的是所有元素  |\n",
    "| count()   | 检索元素在列表中出现的次数 | 详见4.count | 结果是出现次数,而不是列表元素的个数  |\n",
    "| copy()    | 复制列表中的元素  |  详见5.copy       | 返回复制后的新列表  |\n",
    "| sort()    | 将列表中的元素 进行排序 | 详见6.sort  |该方法没有返回值，但是会对列表的对象进行排序   |\n",
    "| reserve()  | 将列表中的元素进行反转  | 详见7.reverse| 所有元素反向排序  |\n",
    "| remove()  | 将某个元素从列表中移除  |  详见8.remove  | 移除列表中某个元素，不改变元素顺序  |\n",
    "| index()   | 检索该元素是否在列表中  | 详见9.index  | 在列表中则输出元素，不在则报错  |\n",
    "| pop()    | 如果元素不在列表中，则报错  | 详见10.pop  | 不在列表中则会报错   |\n",
    "| extend()  |扩展列表中某个元素  |  详见11.extend     | 扩展的是某个具体元素  |\n",
    "| Paragraph  | Text      |          |          |"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5f3df6de",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
